package fun.coding.leetcode;

public class ExcelSheetColumnNumber {

	public static void main(String[] args) {
		ExcelSheetColumnNumber ins = new ExcelSheetColumnNumber();
		
		System.out.println(ins.titleToNumber("AZ"));
	}
	
	/**
	 *      A -> 1
		    B -> 2
		    C -> 3
		    ...
		    Z -> 26
		    AA -> 27
		    AB -> 28
	 */
	public int titleToNumber(String s) {
		if (s == null || s.isEmpty()) return 0;
		
		int sum = 0;
		int count = 0;
		for (int i = s.length() - 1; i >= 0; i--) {
			char c = s.charAt(i);
			sum += Math.pow(26, count)*(c - 'A' + 1);
			count++;
		}
		
		return sum;
    }
	
	

}
